/**
 * Created by zqk on 2018/7/16.
 */
$(document).ready(function () {

    var form = new xhForm($('#xh_form'));
    form.parse();
    var iId=addressUri.getParam('iId');
    form.bindRequired($('#bt_modal_confirm',parent.document));
    //编辑项目
    if(iId!=null){ //edit
        $.ajax({
            url:moduleUrl+'test/getCaseInfo',
            data:{iId:iId},
            type:'POST',
            dataType:'json',
            success:function (data) {
                form.fill(data);
                form.bindRequired($('#bt_modal_confirm',parent.document));
            },
            error:function (data) {
                window.top.xhTop.showError(
                    data.responseJSON.error,
                    data.responseJSON.msg
                );
            }
        });
    }

    //表单提交
    $('#bt_modal_confirm',parent.document).click(function () {
        xhExtra.setBtnLoading($('#bt_modal_confirm',parent.document));
        $('#bt_modal_confirm',parent.document).addClass('disabled');
        $.ajax({
            url:moduleUrl+'test/saveCase',
            data:$('#xh_form').serialize(),
            type:'POST',
            success:function (data) {
                window.top.xhTop.showSuccess(
                    data.msg
                );
                window.top.xhTop.getActiveFrame().caseList.datagrid('clearSelections');
                window.top.xhTop.getActiveFrame().caseList.datagrid('reload');
                window.top.xhTop.closeModal();
            },
            error:function (data) {
                xhExtra.setBtnNormal($('#bt_modal_confirm',parent.document));
                $('#bt_modal_confirm',parent.document).removeClass('disabled');
                window.top.xhTop.showError(
                    data.responseJSON.error,
                    data.responseJSON.msg
                );
            }
        });

    });
    // modalBind.bindClick();

});